﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using TSSControlLibrary;
using TaskSchedulingSystemClassLibrary.IO;

namespace TaskSchedulingSystemForm
{
    /// <summary>
    /// 重定向Console后的标准输入
    /// </summary>
    class UserControlReader:TextReader
    {
        DisPlayIOInfoUserControl userControl = new DisPlayIOInfoUserControl();
        delegate void Voidaction();
        public UserControlReader(DisPlayIOInfoUserControl u)
        {
            userControl = u;
        }
        /// <summary>
        /// 重定向控制台标准输入 从模拟控制台读入一行字符
        /// </summary>
        /// <returns></returns>
        public override string ReadLine()
        {
            string rs = "";
            while (true)
            {
                Thread.Sleep(500);
                Voidaction action = delegate
                {
                    rs = this.userControl.ReadOneLine();
                };
                userControl.BeginInvoke(action);
                if (rs == "")
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
            return rs;
        }      
    }
}
